package com.xingfly.web;

import com.xingfly.web.model.ResponseModel;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by SuperS on 2016/12/22.
 */
@RestController
public class ExceptionController {
    @GetMapping("/401")
    public ResponseModel<?> unauthorized() {
        return ResponseModel.error(HttpStatus.UNAUTHORIZED, "未授权");
    }

    @GetMapping("/403")
    public ResponseModel<?> noAuthority() {
//        return  ResponseEntity.status(HttpStatus.FORBIDDEN).body("没有权限 403");
        return ResponseModel.error(HttpStatus.FORBIDDEN, "没有访问权限");
    }

    @GetMapping("/404")
    public ResponseModel<?> notFound() {
//        return ResponseEntity.status(HttpStatus.NOT_FOUND).body("没有找到该页面 404 ");
        return ResponseModel.error(HttpStatus.NOT_FOUND, "没有找到该页面");

    }

    @GetMapping("/500")
    public ResponseModel<?> serverError() {
        return ResponseModel.error(HttpStatus.INTERNAL_SERVER_ERROR, "服务器错误");
    }
}
